package com.pnnd.utils;

import java.util.Arrays;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class IntTuple {

    private int[] values;

    public static IntTuple empty(int size){
        return fullNum(size,0);
    }

    public static IntTuple fullNum(int size,int num){
        int[] vals = new int[size];

        for(int i=0;i<size;i++){
            vals[i] = num;
        }

        return new IntTuple(vals);
    }

    public int[] toArray(){
        return Arrays.copyOf(this.values,this.values.length);
    }

    public IntTuple(int ...values){
        this.values = values;
    }

    public int size(){
        return this.values.length;
    }

    public int get(int i){
        return this.values[i];
    }

    public void set(int i,int value){
        this.values[i] = value;
    }

    @Override
    public boolean equals(Object other){

        if(other instanceof IntTuple){
            return Arrays.equals(this.values,((IntTuple) other).values);
        }

        return false;
    }

    @Override
    public int hashCode(){
        return Arrays.hashCode(this.values);
    }

    @Override
    public String toString(){

        StringBuilder result = new StringBuilder();

        for(int v:values){
            result.append(",");
            result.append(v);
        }

        return "(" + result.substring(1).toString() + ")";

    }

    public static void main(String[] args){
        String tupleStr = "(3,2,3)";

        Pattern pattern = Pattern.compile("\\d(?<=([,]?))");

        Matcher matcher = pattern.matcher(tupleStr);

        while(matcher.find()){

            System.out.println("count" + matcher.groupCount());

            for(int i=0;i<matcher.groupCount();i++){
                System.out.println(matcher.group(i));
            }
        }
    }
}
